package com.killer.mianshibaodian;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class BaseActivity extends AppCompatActivity {


    private TextView headTitle;
    private Button[] btns = new Button[3];
    private Class[] targetActivities = new Class[]{MainActivity.class, QuestionActivity.class, SearchActivity.class};
    private int[] bottomImgs = new int[]{R.drawable.bottombtn01b, R.drawable.bottombtn02b, R.drawable.bottombtn03b};
    private int[] bottomImgsSelected = new int[]{R.drawable.bottombtn01a, R.drawable.bottombtn02a, R.drawable.bottombtn03a};
    private int i;

    private Button settingBtn;
    //浮动窗口
    private PopupWindow win;

    private static List<Activity> allActivites = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        allActivites.add(this);
        super.onCreate(savedInstanceState);

    }

    protected void init(String title,int index){
        headTitle = (TextView) findViewById(R.id.head_title);
        headTitle.setText(title);

        btns[0] = (Button) findViewById(R.id.bottombtn_01);
        btns[1] = (Button) findViewById(R.id.bottombtn_02);
        btns[2] = (Button) findViewById(R.id.bottombtn_03);

        for (i=0;i<btns.length;i++){
            final int temp = i;
            if (index==i){
                btns[i].setBackgroundResource(bottomImgsSelected[i]);
            }else {
                btns[i].setBackgroundResource(bottomImgs[i]);
                btns[i].setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        Intent intent = new Intent(BaseActivity.this,targetActivities[temp]);
                        startActivity(intent);
                    }
                });
            }
        }
    }
}
